<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../node_modules/react/umd/react.development.js"></script>
    <script src="../node_modules/react-dom/umd/react-dom.development.js"></script>
    <script src="../node_modules/babel-standalone/babel.js"></script>
</head>
<body>
    <div id="app"></div>
    <script type="text/babel">
        class Parent extends React.Component {
            constructor(props) {
                super(props);

                this.state = {
                    domInputValue: 'Huang JX'
                }
                // 受控表单元素
                // input value
                // checkbox, raido checked
                // select.option selected
                // 这些元素表单状态的变化是由 React 控制
                // 非受控表单元素
                // defaultValue

                // 对受控表单元素的操作
                // 1. 初始化一个状态
                // 2. 绑定
                // 3. 实现 onChange 事件
            }

            componentDidMount() {
                console.log(this.refs.reactChild.state.a);
                console.log(this.refs.domInput.value);
            }

            handleChange(event) {
                console.log(event.target.value);
                console.log(this.refs.domInput.domInputValue);
                console.log(this.state.domInputValue);

                this.setState({
                    domInputValue: event.target.value
                });
            }

            render() {
                return (
                    <div>
                        <Child ref="reactChild"/>
                        <input ref="domInput" type="text" value={this.state.domInputValue} onChange={this.handleChange.bind(this)}/>
                    </div>
                );
            }
        }

        class Child extends React.Component {
            constructor(props) {
                super(props);

                this.state = {
                    a: 25
                }
            }

            render() { 
                return (
                    <div>
                       <input type="button" value="子组件按钮" />
                    </div>
                );
            }
        }

        ReactDOM.render(
            <Parent />,
            document.getElementById('app')
        );
    </script>
</body>
</html>